#include "stdafx.h"
#include <CppUnitTest.h>

#include "nef.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace nef;

__declspec(selectany) char THE_MEANING_OF_LIFE[] = "Stuff";

class Val {};

nef_export<Val, Val, THE_MEANING_OF_LIFE> export_val;

class Val1
{
public:
	// In order for embedded to work, this must be a typedef
	typedef nef_export<Val1, Val1, THE_MEANING_OF_LIFE> export0;
};

class Val2 { };

template<>
struct nef_traits<Val2>
{
	typedef nef_export<Val2> export0;
};

namespace nef_unit_test
{
	TEST_CLASS(auto_export_tests)
	{
	public:
		TEST_METHOD(Auto_Simple)
		{
			auto cat = Catalog::Create();

			auto val = cat->GetExportedValue<Val>(THE_MEANING_OF_LIFE, false);

			Assert::IsNotNull(val.get(), L"The exported value was not found.", LINE_INFO());
		}

		TEST_METHOD(Auto_Embedded)
		{
			// Verify that we didn't screw up simple
			Auto_Simple();

			auto cat = Catalog::Create();

			auto val1 = cat->GetExportedValue<Val1>(THE_MEANING_OF_LIFE, false);

			Assert::IsNotNull(val1.get(), L"The exported value was not found.", LINE_INFO());

			std::vector<std::shared_ptr<Val1>> allVals;
			cat->GetExportedValues<Val1>(allVals, THE_MEANING_OF_LIFE);

			Assert::AreEqual((int)allVals.size(), 1, L"The number of exports was too high. This may mean that portions of the export system are executed multiple times.", LINE_INFO());
		}

		TEST_METHOD(Auto_Traits)
		{
			auto cat = Catalog::Create();

			auto val2 = cat->GetExportedValue<Val2>(NO_CONTRACT, false);

			Assert::IsNotNull(val2.get(), L"The specified value could not be found.", LINE_INFO());
		}
	};
}